package com.richest.api.controller.cn.client.admart;

import java.math.BigDecimal;
import java.util.*;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.web.bind.annotation.*;

import com.richest.api.service.IAdmartService;
import com.richest.util.CallResults;

/**
 * 商户表 后端接口
 * 
 * @author zhaohongchao
 * @email 70375739@qq.com
 * @date 2019-02-25 12:55:22
 */
@RestController
@RequestMapping("/AdmartController")
@Api(value = "商户接口")
@EnableAutoConfiguration
public class ApiAdmartController {
	@Autowired
	private IAdmartService admartService;

	/**
	 * 首页推荐商户列表 按距离进行排序
	 * 
	 * @author zhaohongchao 2019/2/25 0025
	 * @param
	 * @return
	 **/
	@RequestMapping(value = "getRecommendList", produces = "application/json;charset=UTF-8")
	@ApiOperation(notes = "首页推荐商户列表", value = "首页推荐商户列表", httpMethod = "GET")
	@ApiImplicitParams({
			@ApiImplicitParam(name = "longitude", value = "横坐标", required = true, paramType = "query", dataType = "BigDecimal"),
			@ApiImplicitParam(name = "latitude", value = "纵坐标", required = true, paramType = "query", dataType = "BigDecimal"),
			@ApiImplicitParam(name = "level", value = "检索级别：一级列表--1；二级列表--2", required = true, paramType = "query", dataType = "String"),
			@ApiImplicitParam(name = "pageNo", value = "页码", required = true, paramType = "query", dataType = "Integer", defaultValue = "0"),
			@ApiImplicitParam(name = "pageSize", value = "记录数", required = true, paramType = "query", dataType = "Integer", defaultValue = "5") })
	public CallResults getRecommendList(@RequestParam BigDecimal longitude, @RequestParam BigDecimal latitude,
			@RequestParam String level, @RequestParam Integer pageNo, @RequestParam Integer pageSize) {
		// 根据类型查询促销活动分类
		Map<String, Object> params = new HashMap();
		params.put("longitude", longitude);
		params.put("latitude", latitude);
		params.put("level", level);
		params.put("page", pageNo);
		params.put("size", pageSize);

		List<Map<String, Object>> lst = admartService.selectList(params);

		return CallResults.ok().put("data", lst);
	}

	/**
	 * 筛选商户列表 按距离进行排序
	 * 
	 * @author zhaohongchao 2019/3/5 0005
	 * @param
	 * @return
	 **/
	@RequestMapping(value = "getScreenList", produces = "application/json;charset=UTF-8")
	@ApiOperation(notes = "商户列表", value = "商户列表", httpMethod = "GET")
	@ApiImplicitParams({
			@ApiImplicitParam(name = "longitude", value = "横坐标", required = true, paramType = "query", dataType = "BigDecimal"),
			@ApiImplicitParam(name = "latitude", value = "纵坐标", required = true, paramType = "query", dataType = "BigDecimal"),
			@ApiImplicitParam(name = "level", value = "检索级别：一级列表--1；二级列表--2", required = true, paramType = "query", dataType = "Integer"),
			@ApiImplicitParam(name = "screen_type", value = "筛选类型:hots 热门，distance 距离，category 分类， all 全部， praise 好评，sales 销量", required = true, paramType = "query", dataType = "String"),
			@ApiImplicitParam(name = "screen_value", value = "筛选值,当类型为分类时:全部 1；面食粥点 2；汉堡披萨 3；香锅冒菜 4；简餐便当5；日韩料理 6；轻食西餐 7；小吃炸串 8；地方菜系 9", required = true, paramType = "query", dataType = "String"),
			@ApiImplicitParam(name = "pageNo", value = "页码", required = true, paramType = "query", dataType = "Integer", defaultValue = "0"),
			@ApiImplicitParam(name = "pageSize", value = "记录数", required = true, paramType = "query", dataType = "Integer", defaultValue = "5") })
	public CallResults getScreenList(@RequestParam BigDecimal longitude, @RequestParam BigDecimal latitude,
			@RequestParam Integer level, @RequestParam String screen_type, @RequestParam String screen_value,
			@RequestParam Integer pageNo, @RequestParam Integer pageSize) {
		// hots 热门，distance 距离，category 分类， all 全部， praise 好评，sales 销量
		List<Map<String, Object>> lst = new ArrayList<>();
		switch (screen_type) {
		case "hots": {// 热门
			Map<String, Object> params = new HashMap();
			params.put("longitude", longitude);
			params.put("latitude", latitude);
			params.put("hots", 1);
			params.put("page", pageNo);
			params.put("size", pageSize);

			lst = admartService.selectList(params);
		}
			break;
		case "distance": { // 距离
			Map<String, Object> params = new HashMap();
			params.put("longitude", longitude);
			params.put("latitude", latitude);
			params.put("page", pageNo);
			params.put("size", pageSize);

			lst = admartService.selectList(params);
		}
			break;
		case "category": {// 分类
			Map<String, Object> params = new HashMap();
			params.put("longitude", longitude);
			params.put("latitude", latitude);
			params.put("level", level);
			params.put("category", screen_value);
			params.put("page", pageNo);
			params.put("size", pageSize);

			lst = admartService.selectList(params);
		}
			break;
		case "all": {// 全部
			Map<String, Object> params = new HashMap();
			params.put("longitude", longitude);
			params.put("latitude", latitude);
			params.put("page", pageNo);
			params.put("size", pageSize);

			lst = admartService.selectList(params);
		}
			break;
		case "praise": {// 好评
			Map<String, Object> params = new HashMap();
			params.put("longitude", longitude);
			params.put("latitude", latitude);
			params.put("praise", 1);
			params.put("page", pageNo);
			params.put("size", pageSize);

			lst = admartService.selectList(params);
		}
			break;
		case "sales": {// 销量
			Map<String, Object> params = new HashMap();
			params.put("longitude", longitude);
			params.put("latitude", latitude);
			params.put("sales", 1);
			params.put("page", pageNo);
			params.put("size", pageSize);

			lst = admartService.selectList(params);
		}
			break;
		default:
			return CallResults.error("检索方式不存在，请重新尝试！");
		}

		return CallResults.ok().put("data", lst);
	}

	/**
	 * 获取包房、桌信息
	 * 
	 * @author zhaohongchao 2019/2/25 0025
	 * @param
	 * @return
	 **/
	@RequestMapping(value = "getDiningTable", produces = "application/json;charset=UTF-8")
	@ApiOperation(notes = "获取店铺的包房、桌信息", value = "获取店铺的包房、桌信息", httpMethod = "GET")
	@ApiImplicitParam(name = "admartId", value = "店铺id", required = true, paramType = "query", dataType = "Long")
	public CallResults getDiningTable(@RequestParam Long admartId) {
		return admartService.getDiningTable(admartId);
	}
}
